package org.java.detail.service.impl;

import org.java.detail.feignclient.SkuClient;
import org.java.detail.service.DetailService;
import org.java.item.entity.Sku;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author WHQ
 * @version 1.0
 * @date 2022-3-10 0010 上午 11:01
 */
@Service
public class DetailServiceImpl implements DetailService {
    @Resource
    private SkuClient skuClient;
    /**
     * 为了方便进行页面静态化的处理，查询到的商品信息封装成map进行返回
     * 返回的对象信息如下:
     * Sku(id=2600242,
     * spuId=1,
     * title=华为 G9 青春版 白色 移动联通电信4G手机 双卡双待,
     * images=http://img.shopping.com/images/9/15/1524297313793.jpg,
     * price=85000,
     * inventory=库存
     * indexes=,
     * ownSpec=,
     * enable=true,
     * createTime=Sat Apr 21 15:55:14 CST 2018,
     * lastUpdateTime=Sun Feb 13 17:37:46 CST 2022)
     * @param
     * @return
     */
    @Override
    public Map findSkuDetailById(Long id) {
        System.out.println(id);
        Sku sku = skuClient.findById(id);
        System.out.println(sku);
        Map map=new HashMap<>(10000);
        map.put("skuId",id);
        map.put("spuId",sku.getSpuId());
        map.put("title",sku.getTitle());
        map.put("images",sku.getImages());
        map.put("price",sku.getPrice());
        return map;
    }
}
